using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Threading;
namespace TciNewsReader_2014_04.VmHelpers
{
    public sealed class Stats : INotifyPropertyChanged
    {
        // binded to the status bar
        private int _numberOfFeeds;
        private int _numberOfFilteredItems;
        private int _numberOfHistoryItems;
        private int _numberOfIncludedFeeds;
        private int _numberOfSeenItems;
        private int _numberOfVisibleItems;
        private int _totalNumberOfItems;
        public Stats()
        {
            Clear();
        }
        public int TotalNumberOfItems
        {
            [DebuggerStepThrough] get { return _totalNumberOfItems; }
            [DebuggerStepThrough]
            set
            {
                if (value != _totalNumberOfItems)
                {
                    _totalNumberOfItems = value;
                    OnPropertyChanged("TotalNumberOfItems");
                }
            }
        }
        public int NumberOfIncludedFeeds
        {
            [DebuggerStepThrough] get { return _numberOfIncludedFeeds; }
            [DebuggerStepThrough]
            set
            {
                if (value != _numberOfIncludedFeeds)
                {
                    _numberOfIncludedFeeds = value;
                    OnPropertyChanged("NumberOfIncludedFeeds");
                }
            }
        }
        public int NumberOfFilteredItems
        {
            [DebuggerStepThrough] get { return _numberOfFilteredItems; }
            [DebuggerStepThrough]
            set
            {
                if (value != _numberOfFilteredItems)
                {
                    _numberOfFilteredItems = value;
                    OnPropertyChanged("NumberOfFilteredItems");
                }
            }
        }
        public int NumberOfFeeds
        {
            [DebuggerStepThrough] get { return _numberOfFeeds; }
            [DebuggerStepThrough]
            set
            {
                if (value != _numberOfFeeds)
                {
                    _numberOfFeeds = value;
                    OnPropertyChanged("NumberOfFeeds");
                }
            }
        }
        public int NumberOfSeenItems
        {
            [DebuggerStepThrough] get { return _numberOfSeenItems; }
            [DebuggerStepThrough]
            set
            {
                if (value != _numberOfSeenItems)
                {
                    _numberOfSeenItems = value;
                    OnPropertyChanged("NumberOfSeenItems");
                }
            }
        }
        public int NumberOfVisibleItems
        {
            [DebuggerStepThrough] get { return _numberOfVisibleItems; }
            [DebuggerStepThrough]
            set
            {
                if (value != _numberOfVisibleItems)
                {
                    _numberOfVisibleItems = value;
                    OnPropertyChanged("NumberOfVisibleItems");
                }
            }
        }
        public int NumberOfHistoryItems
        {
            [DebuggerStepThrough] get { return _numberOfHistoryItems; }
            [DebuggerStepThrough]
            set
            {
                if (value != _numberOfHistoryItems)
                {
                    _numberOfHistoryItems = value;
                    OnPropertyChanged("NumberOfHistoryItems");
                }
            }
        }
        public void Clear()
        {
            NumberOfFeeds = 0;
            NumberOfFilteredItems = 0;
            NumberOfIncludedFeeds = 0;
            TotalNumberOfItems = 0;
            NumberOfSeenItems = 0;
            NumberOfHistoryItems = 0;
        }
        public override string ToString()
        {
            string result = String.Format("{0}/{1}/{2}/{3}/{4}",
                NumberOfFeeds,
                NumberOfIncludedFeeds,
                TotalNumberOfItems,
                NumberOfFilteredItems,
                NumberOfSeenItems);
            return result;
        }
        #region INotifyPropertyChanged Implementation
        public event PropertyChangedEventHandler PropertyChanged;
        private void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = Interlocked.CompareExchange(ref PropertyChanged, null, null);
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(name));
            }
        }
        #endregion
    }
}